package com.bjbn.controller;

import com.bjbn.dto.*;
import com.bjbn.service.Webapi4SimpService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import reactor.core.publisher.Mono;

import java.util.Map;

/**
 * 航空安保一体化平台API控制器
 *
 * @author bjbn
 */
@RestController
@RequestMapping("/CAN/SIMP/securityIntegratedManagementPlatform/V1")
@Tag(name = "航空安保一体化平台API", description = "航空安保一体化平台相关接口")
public class SimpController {

    @Autowired
    private Webapi4SimpService webapiService;

    /**
     * 3.1.1 人像检索-分析
     */
    @PostMapping("/assupUsers/getFaceVectorByMinioUrls")
    @Operation(summary = "人像检索-分析", description = "人脸检测：传入一张人脸图片，检测人脸信息返回")
    public Mono<ResponseEntity<Map<String, Object>>> faceDetect(@RequestBody SimpFaceDetectRequest request) {
        return webapiService.faceDetect(request)
                .map(ResponseEntity::ok)
                .defaultIfEmpty(ResponseEntity.noContent().build());
    }

    /**
     * 3.1.2 人像检索-以图搜图+轨迹检索
     */
    @PostMapping("/getPageListByUserPicUnionDynamic")
    @Operation(summary = "人像检索-以图搜图+轨迹检索", description = "人像检索-以图搜图，图片搜索人像档案以便查询轨迹与抓拍记录")
    public Mono<ResponseEntity<Map<String, Object>>> faceSearch(
            @RequestParam(defaultValue = "10") Long pageSize,
            @RequestParam(defaultValue = "1") Long page,
            @RequestBody SimpFaceSearchRequest request) {
        return webapiService.faceSearch(pageSize, page, request)
                .map(ResponseEntity::ok)
                .defaultIfEmpty(ResponseEntity.noContent().build());
    }

    /**
     * 3.1.3 轨迹检索（携带抓拍信息）
     */
    @PostMapping("/api/iotassup/guest/assupPersonnel/getPageListByUserPicUnionDynamicWithCaptureRecords")
    @Operation(summary = "轨迹检索（携带抓拍信息）", description = "轨迹检索（携带抓拍信息）")
    public Mono<ResponseEntity<Map<String, Object>>> trajectoryRetrieval(
            @RequestBody SimpTrajectoryRetrievalRequest request) {
        return webapiService.trajectoryRetrieval(request)
                .map(ResponseEntity::ok)
                .defaultIfEmpty(ResponseEntity.noContent().build());
    }

    /**
     * 3.1.4 人像检索-属性检索
     */
    @PostMapping("/getPageListByUserPicUnionProperty")
    @Operation(summary = "人像检索-属性检索", description = "人脸属性检索：检索")
    public Mono<ResponseEntity<Map<String, Object>>> faceAttributeSearch(
            @RequestParam(defaultValue = "10") Long pageSize,
            @RequestParam(defaultValue = "1") Long page,
            @RequestBody SimpFaceAttributeRequest request) {
        return webapiService.faceAttributeSearch(pageSize, page, request)
                .map(ResponseEntity::ok)
                .defaultIfEmpty(ResponseEntity.noContent().build());
    }

    /**
     * 3.1.5 智能人像-抓拍记录 以图搜图
     */
    @PostMapping("/getCaptureRecordsByPic")
    @Operation(summary = "智能人像-抓拍记录以图搜图", description = "根据传入图片与相似度阈值检索抓拍记录，根据相似度排序返回抓拍记录")
    public Mono<ResponseEntity<Map<String, Object>>> captureSearch(
            @RequestParam(defaultValue = "10") Long pageSize,
            @RequestParam(defaultValue = "1") Long page,
            @RequestBody SimpCaptureSearchRequest request) {
        return webapiService.captureSearch(pageSize, page, request)
                .map(ResponseEntity::ok)
                .defaultIfEmpty(ResponseEntity.noContent().build());
    }

    /**
     * 3.1.6 人像检索-抓拍详情查询
     */
    @PostMapping("/getCaptureRecordsByVO/snapshotDetailsQuery")
    @Operation(summary = "人像检索-抓拍详情查询", description = "抓拍详情查询")
    public Mono<ResponseEntity<Map<String, Object>>> captureDetailQuery(@RequestBody SimpCaptureDetailRequest request) {
        return webapiService.captureDetailQuery(request)
                .map(ResponseEntity::ok)
                .defaultIfEmpty(ResponseEntity.noContent().build());
    }

    /**
     * 3.1.7 人脸相似度比对
     */
    @PostMapping("/assupUsers/comPics")
    @Operation(summary = "人脸相似度比对", description = "人脸相似度比对：传入2张人脸图片，进行人脸比对，反馈比对识别分（0-1)")
    public Mono<ResponseEntity<Map<String, Object>>> faceCompare(@RequestBody SimpFaceCompareRequest request) {
        return webapiService.faceCompare(request)
                .map(ResponseEntity::ok)
                .defaultIfEmpty(ResponseEntity.noContent().build());
    }

    /**
     * 3.1.8 人脸1：N比对
     */
    @PostMapping("/getPageListByUserPicUnionDynamic/groupRecog")
    @Operation(summary = "人脸1：N比对", description = "人脸1：N比对，传入需识别人脸图片及对应识别库，反馈人脸图片在识别库中识别情况")
    public Mono<ResponseEntity<Map<String, Object>>> face1NCompare(
            @RequestParam(defaultValue = "10") Long pageSize,
            @RequestParam(defaultValue = "1") Long page,
            @RequestBody SimpFace1NRequest request) {
        return webapiService.face1NCompare(pageSize, page, request)
                .map(ResponseEntity::ok)
                .defaultIfEmpty(ResponseEntity.noContent().build());
    }

    /**
     * 3.1.9 检索图片中人脸的建档记录
     */
    @PostMapping("/getPageListByUserPicUnionDynamic/trackSearchPid")
    @Operation(summary = "检索图片中人脸的建档记录", description = "检索上传的图片中人脸的建档记录，建档记录由用户进行手动选择，用于后续根据选择的建档ID查询轨迹")
    public Mono<ResponseEntity<Map<String, Object>>> trackSearchPid(
            @RequestParam(defaultValue = "10") Long pageSize,
            @RequestParam(defaultValue = "1") Long page,
            @RequestBody SimpTrackSearchPidRequest request) {
        return webapiService.trackSearchPid(pageSize, page, request)
                .map(ResponseEntity::ok)
                .defaultIfEmpty(ResponseEntity.noContent().build());
    }

    /**
     * 3.1.10 检索人脸建档的轨迹数据
     */
    @PostMapping("/getCaptureRecordsByVO")
    @Operation(summary = "检索人脸建档的轨迹数据", description = "根据跟定的抓拍轨迹建档ID，检索选择时间段内对应的轨迹点数据，根据轨迹点数据即可在 GIS 地图上对轨迹进行绘制和操作")
    public Mono<ResponseEntity<Map<String, Object>>> trackSearch(@RequestBody SimpTrackSearchRequest request) {
        return webapiService.trackSearch(request)
                .map(ResponseEntity::ok)
                .defaultIfEmpty(ResponseEntity.noContent().build());
    }

    /**
     * 3.1.11 检索人脸建档的轨迹抓拍详情数据
     */
    @PostMapping("/getCaptureRecordsByVO/trackSearchDetail")
    @Operation(summary = "检索人脸建档的轨迹抓拍详情数据", description = "根据给定的人脸建档ID，检索给定时间范围内的人员轨迹抓拍详情数据，包括沿途所有抓拍相机所抓拍的信息，后续可以根据抓拍信息进行视频片段的下载")
    public Mono<ResponseEntity<Map<String, Object>>> trackSearchDetail(@RequestBody SimpTrackSearchDetailRequest request) {
        return webapiService.trackSearchDetail(request)
                .map(ResponseEntity::ok)
                .defaultIfEmpty(ResponseEntity.noContent().build());
    }

    /**
     * 3.1.12 下载轨迹抓拍详情视频
     */
    @GetMapping("/assupHlsSegment/getBlobvirtualM3u8")
    @Operation(summary = "下载轨迹抓拍详情视频", description = "根据给定的轨迹详情ID，下载对应的抓拍视频，每条详情信息对应一个相机设备抓拍到的时间段")
    public Mono<ResponseEntity<Map<String, Object>>> trackVideo(
            @Parameter(description = "摄像头编码", required = true) @RequestParam String streamKey,
            @Parameter(description = "抓拍时间点", required = true) @RequestParam Long timestamp) {
        return webapiService.trackVideo(streamKey, timestamp)
                .map(ResponseEntity::ok)
                .defaultIfEmpty(ResponseEntity.noContent().build());
    }

    /**
     * 3.1.13 人员结构化信息查询（特征查询）
     */
    @PostMapping("/api/iotassup/guest/assupUsers/getNewStructuredPerson")
    @Operation(summary = "人员结构化信息查询（特征查询）", description = "人员结构化信息查询（特征查询）")
    public Mono<ResponseEntity<Map<String, Object>>> getNewStructuredPerson(
            @RequestBody SimpStructuredPersonRequest request) {
        return webapiService.structuredPerson(request.getPageSize(), request.getPage(), request)
                .map(ResponseEntity::ok)
                .defaultIfEmpty(ResponseEntity.noContent().build());
    }
} 